package com.wcl.demo.ui.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.baidu.mapapi.search.core.PoiInfo;
import com.wcl.demo.R;

import java.util.List;

/**
 * Created by dllo on 15/12/4.
 */
public class FindAdapter extends RecyclerView.Adapter<FindAdapter.FindAdapterViewHolder> {
    private List<PoiInfo> results;

    public void addData(List<PoiInfo> results) {
        this.results = results;
        notifyDataSetChanged();
    }


    public class FindAdapterViewHolder extends RecyclerView.ViewHolder {
        private TextView search_itemTv;
        private LinearLayout search_linearlayout;
        private int position;

        public FindAdapterViewHolder(View itemView) {
            super(itemView);
            search_itemTv = (TextView) itemView.findViewById(R.id.search_itemTv);
            search_linearlayout = (LinearLayout) itemView.findViewById(R.id.search_linearlayout);
        }

    }

    @Override
    public FindAdapterViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View view = inflater.inflate(R.layout.fragment_find_item, null);
        return new FindAdapterViewHolder(view);
    }

    @Override
    public void onBindViewHolder(FindAdapterViewHolder holder, int position) {
        if (results != null) {
            holder.search_itemTv.setText(results.get(position).name);
        }
        holder.position = position;
    }

    @Override
    public int getItemCount() {
        return results != null && results.size() > 0 ? results.size() : 0;
    }
}
